#!/usr/bin/env python3
# coding:utf-8
import asyncio
import aiomqtt

async def main():
    async with aiomqtt.Client('127.0.0.1') as mqtt:
        await mqtt.subscribe('test/topic1')
        await mqtt.subscribe('test/topic2')
        async for msg in mqtt.messages:
            if msg.topic.matches('test/topic1'):
                print('topic1:', msg.topic, msg.payload)
            elif msg.topic.matches('test/topic2'):
                print('topic2:', msg.topic, msg.payload)

if __name__ == '__main__':
    asyncio.run(main())